from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import redirect
from web import models
from django.conf import settings


class AuthMiddleware(MiddlewareMixin):
    def process_request(self, request):
        """ 如果⽤户已登录，则request中赋值 """
        user_id = request.session.get('user_id', 0)
        user_obj = models.UserInfo.objects.filter(id=user_id).first()
        request.user_obj = user_obj
